package com.dianping.cat.home.jar.transform;

import com.dianping.cat.home.jar.IEntity;
import com.dianping.cat.home.jar.IVisitor;
import com.dianping.cat.home.jar.entity.Domain;
import com.dianping.cat.home.jar.entity.Jar;
import com.dianping.cat.home.jar.entity.JarReport;
import com.dianping.cat.home.jar.entity.Machine;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private JarReport m_jarReport;


  public DefaultMerger() {}

  public DefaultMerger(JarReport jarReport) {
/*  22 */     this.m_jarReport = jarReport;
/*  23 */     this.m_objs.push(jarReport);
  }


/*  27 */   public JarReport getJarReport() { return this.m_jarReport; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }


/*  41 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  45 */   protected void mergeJar(Jar to, Jar from) { to.mergeAttributes(from); }



/*  49 */   protected void mergeJarReport(JarReport to, JarReport from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }



  public void visitDomain(Domain from) {
/*  58 */     Domain to = (Domain)this.m_objs.peek();

/*  60 */     mergeDomain(to, from);
/*  61 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
/*  65 */     for (Machine source : from.getMachines().values()) {
/*  66 */       Machine target = to.findMachine(source.getId());

/*  68 */       if (target == null) {
/*  69 */         target = new Machine(source.getId());
/*  70 */         to.addMachine(target);
      }

/*  73 */       this.m_objs.push(target);
/*  74 */       source.accept(this);
/*  75 */       this.m_objs.pop();
    }
  }


  public void visitJar(Jar from) {
/*  81 */     Jar to = (Jar)this.m_objs.peek();

/*  83 */     mergeJar(to, from);
/*  84 */     visitJarChildren(to, from);
  }


  protected void visitJarChildren(Jar to, Jar from) {}


  public void visitJarReport(JarReport from) {
/*  92 */     JarReport to = (JarReport)this.m_objs.peek();

/*  94 */     mergeJarReport(to, from);
    visitJarReportChildren(to, from);
  }

  protected void visitJarReportChildren(JarReport to, JarReport from) {
/*  99 */     for (Domain source : from.getDomains().values()) {
/* 100 */       Domain target = to.findDomain(source.getId());

/* 102 */       if (target == null) {
/* 103 */         target = new Domain(source.getId());
/* 104 */         to.addDomain(target);
      }

/* 107 */       this.m_objs.push(target);
/* 108 */       source.accept(this);
/* 109 */       this.m_objs.pop();
    }
  }


  public void visitMachine(Machine from) {
/* 115 */     Machine to = (Machine)this.m_objs.peek();

/* 117 */     mergeMachine(to, from);
/* 118 */     visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/* 122 */     for (Jar source : from.getJars()) {
/* 123 */       Jar target = null;

/* 125 */       if (target == null) {
/* 126 */         target = new Jar();
/* 127 */         to.addJar(target);
      }

/* 130 */       this.m_objs.push(target);
/* 131 */       source.accept(this);
/* 132 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/jar/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */